package Interface;

import Book.BookList;

import java.util.Scanner;

/**
 * @Author YuanYuan
 * @Date 2022/5/18
 * @Time 10:39
 */
public class DelBook implements INterface{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要删除的书名: ");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getNumber(); i++) {
            if(bookList.getBooks(i).getName().equals(name)) {
                for (int j = i; j < bookList.getNumber()-1; j++) {
                    bookList.setBooks(j,bookList.getBooks(j+1));
                }
                bookList.setBooks(bookList.getNumber()-1,null);
                bookList.setNumber(bookList.getNumber()-1);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("图书馆没有这本书哦~");
        return;

    }
}
